package client;

import gui.common.msg.SysMessage;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;


import data.Forum;
import data.Group;
import data.User;


import server.DataServer;

public class DataClient extends UnicastRemoteObject{

	private static final long serialVersionUID = 1L;

	private DataServer dataServer;
	private String clientName;
	
	private User currentUser=null;
	private Group currentGroup=null;
	private Forum currentForum=null;

	
	public User getCurrentUser() {
		return currentUser;
	}
	public void setCurrentUser(User currentUser) {
		this.currentUser = currentUser;
	}
	public Group getCurrentGroup() {
		return currentGroup;
	}
	public void setCurrentGroup(Group currentGroup) {
		this.currentGroup = currentGroup;
	}
	public Forum getCurrentForum() {
		return currentForum;
	}
	public void setCurrentForum(Forum currentForum) {
		this.currentForum = currentForum;
	}
	public DataClient() throws RemoteException{
		
	}
	public void connectServer(){
		clientName=getClientName();
		try {
			dataServer=(DataServer)Naming.lookup("//localhost/DataServer");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	private String getClientName(){
		String result=null;
		result=Long.toString(System.currentTimeMillis());
		return result;
	}
	public DataServer getRemoteServer(){
		return dataServer;
	}
	public static void main(String[] args) {
		try {
			DataClient dc=new DataClient();
			dc.connectServer();
			SysMessage msg=dc.dataServer.loginUser("scm", "123456");
			System.out.println(msg.subject);
			if(msg.data!=null){
				System.out.println(((User)msg.data).toString());
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
